angular.module('start.common.feedback.ctrl', [])

  .controller('FeedbackCtrl', function($scope, $ionicPopup, $rootScope, $$CommonService, $ionicLoading, $location) {
    console.log("FeedbackCtrl");
    //创建对象接收意见反馈
    $scope.feedBacks = {
      // id: $rootScope.userData.id,
      comment: "",
      isAnonymous: 0
    };
    //一个确认对话框
    $scope.surealert = function() {
      //确认对话款内容
      var confirmPopup = $ionicPopup.confirm({
        title: "反馈",
        template: "确定要反馈吗?",
        cancelText: "取消",
        okText: "确定"
      });
      confirmPopup.then(function(res) {
        //如果提交
        if (res) {
          //意见反馈校验
          if (!$scope.feedBacks.comment) {
            $ionicLoading.show({
              template: "意见反馈不能为空",
              noBackdrop: true,
              duration: 1500
            });
            return;
          }
          //调service反馈的feedBackUser()方法
          $$CommonService.feedBackUser($scope.feedBacks)
            .then(function(res) {
              console.log(res);
              //如果成功
              $ionicLoading.show({
                template: res.msg,
                noBackdrop: true,
                duration: 1500
              });
              $location.path("tab/user");

            });
        } else {
          $ionicLoading.show({
            template: "取消反馈",
            noBackdrop: true,
            duration: 1500
          });
        }
      });
    };
  });
